package com.kgcx.system.service;

import com.kgcx.common.constant.Cons;
import com.kgcx.system.domain.OperationInfo;
import com.kgcx.system.mapper.OperationInfoMapper;
import com.kgcx.system.rabbitmq.producer.OperationInfoProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 吴刚林
 * @date 2017/11/20
 */
@Service
public class OperationInfoService {
    @Autowired
    private OperationInfoMapper operationInfoMapper;

    @Autowired
    private OperationInfoProducer operationInfoProducer;


    public void getOperationInfo(OperationInfo operationInfo) {
        operationInfoMapper.selectOneActive(operationInfo);
    }
    /**
     * 根据ID查询公司运营规模信息放到MQ里面给监管平台
     * @param kid
     * @return
     */
    public OperationInfo getOperationInfoById(Long kid) {
       OperationInfo operationInfo= operationInfoMapper.selectByPrimaryKey(kid);
       operationInfoProducer.addOperationInfo(operationInfo);
       return operationInfo;
    }
    @Transactional(rollbackFor = Exception.class)
    public void addOperationInfo(OperationInfo operationInfo) {
        operationInfoMapper.insertSelective(operationInfo);

        operationInfoProducer.addOperationInfo(operationInfo);

    }

    @Transactional(rollbackFor = Exception.class)
    public void updateOperationInfo(OperationInfo operationInfo) {
        operationInfoMapper.updateByPrimaryKeySelective(operationInfo);

        operationInfoProducer.updateOperationInfo(operationInfo);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeOperationInfo(Long kid) {
        OperationInfo operationInfo = new OperationInfo();
        operationInfo.setKid(kid);
        operationInfo.setStatus(Cons.COMMON_STATUS_DELETE);
        operationInfoMapper.updateByPrimaryKeySelective(operationInfo);

        operationInfoProducer.deleteOperationInfo(operationInfo);
    }
}
